<template>
    
    <div class="bg-img">
        <div class="bg" :style="{display:isShowLogin}">
            <div class="logoBox">
                <img src="./assets/icon_xt_logo2.png" alt="" class="logo">
                <div>
                        <a href="">学校官网</a>|<a href="">操作指南</a>
                </div>
            </div>
            <div class="login">
                
                <div class="login-header">
                    <div class="QC-code">
                        <!-- <i class="fa fa-qrcode fa-2x"></i> -->
                        <img src="./assets/icon_login_qcode.png" alt="" class="QcCodImg">
                    </div>
                    
                    </div>
                    <div class="identity">
                        <div>账号登录</div>
                    </div>
                    <div class="login-info">
                        
                        <div class="username-css">
                            <div><i class="fa fa-user fa-2x"></i></div><input type="text" name="username" v-model="username" @input="handleInputChange"><br>
                        </div>
                        <div class="password-css">
                            <div><i class="fa fa-key fa-2x"></i></div><input  type="password" name="password" v-model="password" @input="handleInputChange"><br>
                        </div>
                        
                        <div class="btn">
                        <button class="denglu" type="submit" :disabled="isButtonDisabled" :style="dengluStyle" @click="sendData">登录</button>
                            <div class="regiter">没有用户？请<a href="/#/register">注册</a></div>
                        </div>
                        
                    </div>

                
                    <!-- <div class="btn" v-show="isShowZhuce" @click="ToRegister">
                        <button class="zhuce">注册</button>
                    </div> -->
            </div>
            <div class="bottomBox">
                <img src="./assets/icon_xt_notice1.png" alt="" class="loginTip">
                <div class="text">
                    <p>
                        <img src="./assets/icon_xt_notice2.png" alt="">
                        <span>推荐使用360(极速模式)、搜狗(高速模式)、 IE(IE9及以上版本)、谷歌、Microsoft Edge浏览器访问系统，建议在1920*1080分辨率下使用。</span>
                    </p>
                    <p><img src="./assets/icon_xt_notice2.png" alt=""><span>账号规则：学生为学号，教工为工号，如忘记密码请联系所在学院教学秘书重置。</span></p>
                    <p><img src="./assets/icon_xt_notice2.png" alt=""><span>服务支持：xxzx@shanheu.edu.cn，或可前往学生一站式服务中心10号窗口处理。</span></p>
                </div>
                <div class="cus-copy">Copyright © 2024 Shanhe University All Rights Reserved 山河大学信息中心 <br><a href="https://beian.miit.gov.cn/" target="_blank">鄂ICP备2023010506号-1</a></div>
                
            </div>
            
        </div>
    </div>
 </template>

<script>
import axios from 'axios'


export default {
    name:'LoginPage',
    data(){
        return {
            identity: '老师登录',
            identityEnglish: 'teacher',
            username: '',
            password: '',
            isShowLogin: 'block',
            dengluStyle:{
                color:'',
                backgroundColor:'',
                cursor:'',
                
            },
            isButtonDisabled: true,
            isShowZhuce: true
        }
    },
    methods:{
        handleInputChange(){
            
            if(this.username === '' | this.password === ''){
                this.dengluStyle.color = ''
                this.dengluStyle.backgroundColor = ''
                this.dengluStyle.cursor = ''
                this.isButtonDisabled = true
            }else{
                this.dengluStyle.color = 'rgb(206, 180, 137)'
                this.dengluStyle.backgroundColor = 'rgb(57, 59, 64)'
                this.dengluStyle.cursor = 'pointer'
                this.isButtonDisabled = false
            }
            

        },
        identityChange(e){
            const active = document.querySelector('.active')
            active.classList.remove('active')
            this.identity = e.target.textContent
            e.target.querySelector('.checked').classList.add('active')
            if(this.identity === '管理员登录'){
                this.isShowZhuce = false
            }else{
                this.isShowZhuce = true
            }
            if(this.identity === '老师登录')
                this.identityEnglish = 'teacher'
            else if(this.identity === '学生登录')
                this.identityEnglish = 'student'
            else if(this.identity === '管理员登录')
                this.identityEnglish = 'admin'

        },
        // sendData1(){
        //     if(this.identityEnglish === 'student'){
        //         this.$router.push({path:'/student' ,query:{username:this.username,identity:this.identityEnglish}})
        //     }else if(this.identityEnglish === 'teacher'){
        //         this.$router.push({path:'/teacher' ,query:{username:this.username,identity:this.identityEnglish}})
        //     }else{
        //         this.$router.push({path:'/admin' ,query:{username:this.username,identity:this.identityEnglish}})
        //     }
        //     localStorage.setItem('username',JSON.stringify(this.username))
        // },
        
        sendData(){
            
            // TODO
            // if(this.identityEnglish === 'student'){
            //     axios.get(`http://127.0.0.1:1145/student?username=${this.username}&password=${this.password}`,
            //     ).then(response => {//TODO
                    
            //         if(response.data.code === 0){
            //             this.$router.push({path:'/student',query: {username:this.username,identity:this.identityEnglish,}}) 
            //             localStorage.setItem('username',JSON.stringify(this.username))
            //             localStorage.setItem('data', JSON.stringify(response.data.data))
            //         }else{
            //             alert('账号或密码错误')
            //         }
                    
            //     }).catch(error => {
            //         this.$router.push({name:'error', query:{error:error}})
            //     })

            // }else if(this.identityEnglish === 'teacher'){
                
            //     const url =`http://127.0.0.1:1145/teacher?username=${this.username}&password=${this.password}`
                
            //     axios.get(url
                
            //     ).then(response => {//TODO
                    
            //         if(response.data.code === 0){
                        
            //             this.$router.push({path:'/teacher',query: {username:this.username,identity:this.identityEnglish,data:response.data.data}}) 
            //             localStorage.setItem('username',JSON.stringify(this.username))
            //             localStorage.setItem('teacherId',JSON.stringify(response.data.data.tnub))
            //             localStorage.setItem('teacherName',response.data.data.tname)
            //             localStorage.setItem('data', JSON.stringify(response.data.data))

            //         }else{
            //             alert('账号或密码错误')
            //         }
                    
            //     }).catch(error => {
            //         this.$router.push({name:'error', query:{error:error}})
            //     })
            // }else {
            //     axios.get(`http://127.0.0.1:1145/admin?username=${this.username}&password=${this.password}`
            //     ).then(response => {//TODO
            //         if(response.data.code === 0){
            //             this.$router.push({path:'/admin',query: {username:this.username,identity:this.identityEnglish,data:response.data.data}}) 
            //             localStorage.setItem('username',JSON.stringify(this.username))
            //             localStorage.setItem('data', JSON.stringify(response.data.data))
            //         }else{
            //             alert('账号或密码错误')
            //         }

            //     }).catch(error => {
            //         this.$router.push({name:'error', query:{error:error}})
            //     })
            // }
            axios.get(`/prod-api/admin?username=${this.username}&password=${this.password}`
                ).then(response => {//TODO
                    if(response.data.code === 1){
                        this.$router.push({path:'/teacher',query: {username:this.username,identity:"teacher",data:response.data.data}}) 
                        localStorage.setItem('teacherId',JSON.stringify(response.data.data.tnub))
                        localStorage.setItem('teacherName',response.data.data.tname)
                        
                    }else if(response.data.code === 0){
                        this.$router.push({path:'/student',query: {username:this.username,identity:"student",data:response.data.data}}) 
                        
                    }
                    else if(response.data.code === 2){
                        this.$router.push({path:'/admin',query: {username:this.username,identity:"admin",data:response.data.data}}) 
                        
                    }
                    else{
                        alert('账号或密码错误')
                    }
                    localStorage.setItem('username',JSON.stringify(this.username))
                    localStorage.setItem('data', JSON.stringify(response.data.data))
                    localStorage.setItem('token', JSON.stringify(response.data.data))
                   
                })

            


        },
        ToRegister(){
            window.location.replace('/#/register')
        },
        close(){
            this.isShowLogin = 'none'
        }

    },
    components: {
        
    },
    created(){
        this.username = this.$route.query.username
    }
}
</script>

<style>
.bg-img{
    width: 100%;
    height: 100%;
    background-image: url('./assets/bgimg.jpeg') ;
    background-size: cover; /* 设置背景图片尺寸为覆盖整个元素 */
    background-repeat: no-repeat; /* 防止背景图片重复 */
    background-position: center; /* 将背景图片放置在元素中心 */
}

.bg{
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, .5);
    z-index: 9999;
    
}

.logoBox{
    width: 100%;
    height: 110px;
    background-color: white;
}

.logoBox img{
    float: left;
    height: 60%;
    width: 40%;
    margin-left: 380px;
    margin-top: 20px;
}

.logoBox div{
    float: left;
    position: absolute;
    right: 20%;
    top: 6%;
}

.logo{
    width: 100%;
    height: 81px;
}

.login{
    background-color:  rgba(255, 255, 255, 0.5);
    width: 342px;
    height: 320px;
    position: absolute;
    top: calc(48vh - 200px);;
    left: calc(74% - 250px);
    border-radius: 10px;
}
/* .login-css input{
    height: 20px;
    padding-left: 10px;
} */

.username-css i{
    margin-left: 6px;
}

.password-css i{
    margin-left: 2px;
}

.login-header{
    width: 100%;
    height: 10px;
}

.QC-code,
.login-close{
    height: 100%;
    width: 50px;
}

.QC-code{
    float: left;
}

.QC-code i{
    margin-left: 10px;
}

.QcCodImg{
    position: absolute;
    right: 0px;
    width: 32px;
    height: 32px;
}

.login-close{
    float: right;
}

.login-header i{
    margin-top: 10px;
    
}

.login-header i:hover{
    color: yellowgreen;
    cursor: pointer;
}

.login-info .username-css div{
    float: left;
    width: 20%;
    height: 100%;
    font-size: 20px;
    /* margin: 12px 10px; */
    border-right: 1px solid rgba(0, 0, 0, .5);
}

.login-info .password-css div{
    float: left;
    width: 20%;
    height: 100%;
    font-size: 20px;
    /* margin: 12px 10px; */
    border-right: 1px solid rgba(0, 0, 0, .5);
}

.login-info .username-css div i{
    margin-top: 1px;
}

.login-info .password-css div i{
    margin-top: 1px;
}

.username-css input{
    width: 80%;
    height: 100%;
    font-size: 20px;
    border-radius: 0px;
    /* margin-top: 12px;
    margin-left: 15px; */
    background-color: transparent;
}

.password-css input{
    width: 80%;
    height: 100%;
    font-size: 20px;
    border-radius: 0px;
    /* margin-top: 12px;
    margin-left: 15px; */
    background-color: transparent;
}

.username-css{
    /* width: 450px; */
    height: 44px;
    border: 1px solid rgb(0,0,0);
    margin: 15px 15px;
   
    border-radius: 0px;
}

.password-css{
    /* width: 450px; */
    height: 44px;
    border: 1px solid rgb(0,0,0);
    margin: 15px 15px;
   
    border-radius: 0px;
}

.username-css input{
    border: none;
}

.password-css input{
    border: none;
}

/* .username-css:hover{
    border: 1px solid rgb(211, 188, 142);
    transition: all 0.3s ease;
}

.password-css:hover{
    border: 1px solid rgb(211, 188, 142);
    transition: all 0.3s ease;
} */

.identity div{

    /* float: left; */
    height: 50px;
    width: 100%;
    /* margin: 0 15px; */
    font-weight: bold;
    font-size: 20px;
    text-align: center;
    line-height: 50px;
    position: relative;
}
/* .identity{
    height: 50px;
}
.identity div{
    float: left;
    height: 50px;
    width: 133px;
    margin: 0 15px;
    font-size: 15px;
    text-align: center;
    line-height: 50px;
    position: relative;
}
.identity div:hover{
    cursor: pointer;
}
.identity .checked{
    width: 35px;
    height: 5px;
    display: none;
    border-radius: 5px;
    background-color: rgb(211, 188, 142);
    position: absolute;
    bottom: 0;
    left: 35px;
}
.login .identity .active{
    display: block;
} */

.login-info{
    width: 100%;
}

.login-info div{
    width: 90%;
    
}

.btn{
    width: 400px;
    height: 40px;
    margin: 50px 16px;
}
.denglu{
    background-color: #342ca4;
    color: white;
}
.btn .denglu,
.btn .zhuce{
    width: 100%;
    height: 100%;
    
    border:none;
    border-radius: 0px;
    /* background-color: #fff; */
}
.btn .zhuce:hover{
    background-color: rgb(57, 59, 64);
    color: rgb(206, 180, 137);
    cursor: pointer;
}
.bottomBox{
    width: 100%;
    height: 180px;
    background-color: white;
    position: absolute;
    bottom: 0px;
}

.bottomBox .loginTip{
    width: 5%;
    position: absolute;
    left: 400px;
}

.text{
    position: absolute;
    left: 470px;
    top: 10px;
}

.text p img {
    width: 12px;
    margin-right: 3px;
}

.cus-copy {
    width: 100%;
    height: 16px;
    line-height: 16px;
    text-align: center;
    color: #5a5a5a;
    font-size: 12px;
    position: absolute;
    bottom: 50%;
}

.regiter{
    text-align: center;
    margin-top: 8px;
}
</style>